package BanyuanClub.Study.Day0308;

public class MyRunnable implements Runnable{
    @Override
    public void run() {
        //实现Runnable接口的写法
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //获取当前正在运行的线程对象
            System.out.println(Thread.currentThread() + ":" + i);
        }
    }

    public static void main(String[] args) {
        Thread myr1 = new Thread(new MyRunnable()) ;
        Thread myr2 = new Thread(new MyRunnable()) ;
        myr1.start();
        myr2.start();
        //匿名内部类的写法
        new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //获取当前正在运行的线程对象
                System.out.println(Thread.currentThread() + "-" + i);
            }
        }).start();
    }
}
